package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.SecurityUtils;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.CatGodGategory;
import com.happy.cat.project.system.service.ICatGodClassService;
import com.happy.cat.project.system.service.ICatGodGategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 大神标签Controller
 *
 * @author verne
 * @date 2020-07-17
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/gategory" )
@Api("大神标签 API")
public class CatGodGategoryController extends BaseController {

    private final ICatGodGategoryService iCatGodGategoryService;

    private final ICatGodClassService catGodClassService;

    /**
     * 查询大神标签列表
     */
    @ApiOperation(value = "查询大神标签列表",notes = "查询大神标签列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:gategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatGodGategory catGodGategory)
    {
        startPage();
        LambdaQueryWrapper<CatGodGategory> lqw = new LambdaQueryWrapper<CatGodGategory>();
        if (StringUtils.isNotBlank(catGodGategory.getGateIcon())){
            lqw.eq(CatGodGategory::getGateIcon ,catGodGategory.getGateIcon());
        }
        if (StringUtils.isNotBlank(catGodGategory.getIntro())){
            lqw.eq(CatGodGategory::getIntro ,catGodGategory.getIntro());
        }
        if (StringUtils.isNotBlank(catGodGategory.getContent())){
            lqw.eq(CatGodGategory::getContent ,catGodGategory.getContent());
        }
        if (catGodGategory.getCreateData() != null){
            lqw.eq(CatGodGategory::getCreateData ,catGodGategory.getCreateData());
        }
        lqw.ge(CatGodGategory::getStatus ,0);
        List<CatGodGategory> list = iCatGodGategoryService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出大神标签列表
     */
    @ApiOperation(value = "导出大神标签列表",notes = "导出大神标签列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:gategory:export')" )
    @Log(title = "大神标签" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(CatGodGategory catGodGategory) {
        LambdaQueryWrapper<CatGodGategory> lqw = new LambdaQueryWrapper<CatGodGategory>(catGodGategory);
        List<CatGodGategory> list = iCatGodGategoryService.list(lqw);
        ExcelUtil<CatGodGategory> util = new ExcelUtil<CatGodGategory>(CatGodGategory. class);
        return util.exportExcel(list, "gategory" );
    }

    /**
     * 获取大神标签详细信息
     */
    @ApiOperation(value = "获取大神标签详细信息",notes = "获取大神标签详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:gategory:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCatGodGategoryService.getById(id));
    }

    /**
     * 新增大神标签
     */
    @ApiOperation(value = "新增大神标签",notes = "新增大神标签",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:gategory:add')" )
    @Log(title = "大神标签" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatGodGategory catGodGategory) {
        catGodGategory.setCreateData(new Date());
        catGodGategory.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatGodGategoryService.save(catGodGategory) ? 1 : 0);
    }

    /**
     * 修改大神标签
     */
    @ApiOperation(value = "修改大神标签",notes = "修改大神标签",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:gategory:edit')" )
    @Log(title = "大神标签" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatGodGategory catGodGategory) {
        return toAjax(iCatGodGategoryService.updateById(catGodGategory) ? 1 : 0);
    }

    /**
     * 删除大神标签
     */
    @ApiOperation(value = "删除大神标签",notes = "删除大神标签",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:gategory:remove')" )
    @Log(title = "大神标签" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}/{status}" )
    public AjaxResult remove(@PathVariable Long[] ids, @PathVariable Integer status) {
        return toAjax(iCatGodGategoryService.lambdaUpdate().set(CatGodGategory::getStatus,status).in(CatGodGategory::getId, (Object) ids).update() ? 1 : 0);
    }
}
